package com.icss.ah.shop.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.icss.ah.base.bean.SyncSelectTree;

@Service
@Transactional
public class ShopApplyService {
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	/**
	 * 获取银行列表
	 * @return
	 */
	public List queryBankList(){
		List list = new ArrayList();
		try {
			list = sqlSessionTemplate.selectList("ShopApplyBean.queryBankList");
			infolog.info("ShopApplyService|queryBankList|list:"+list.size());
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|queryBankList", ex);
		} 
		return list;
	}
	/**
	 * 获取银行列表
	 * @return
	 */
	public List queryProvinceCityList(HashMap hm){
		List list = new ArrayList();
		try {
			list = sqlSessionTemplate.selectList("ShopApplyBean.queryProvinceCityList",hm);
			infolog.info("ShopApplyService|queryBankList|list:"+list.size());
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|queryBankList", ex);
		} 
		return list;
	}
	public List queryProvinceCityList1(HashMap hm){
		List list = new ArrayList();
		try {
			list = sqlSessionTemplate.selectList("ShopApplyBean.queryProvinceCityList1",hm);
			infolog.info("ShopApplyService|queryBankList|list:"+list.size());
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|queryBankList", ex);
		} 
		return list;
	}
	
	/**
	 * 查询店铺名称是否可用
	 * @param shopName
	 * @return
	 */
	public boolean checkShopNameExist(String shopName) {
		boolean result = false;
		try{
			HashMap info = new HashMap();
			info.put("shopName", shopName);
			Integer count = sqlSessionTemplate.selectOne("ShopApplyBean.checkShopNameExist", info);
			infolog.info("ShopApplyService|checkShopNameExist|count:"+count);
			if(count>0){
				result = false;
			} else {
				result = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("ShopApplyService|checkShopNameExist", e);
		}
		return result;
	}
	/**
	 * 验证对公账户是否可用
	 * @param shopName
	 * @return
	 */
	public boolean checkBankAccount(HashMap info) {
		boolean result = false;
		try{
			String card_length = sqlSessionTemplate.selectOne("ShopApplyBean.checkBankAccount", info);
			infolog.info("ShopApplyService|checkBankAccount|card_length:"+card_length);
			String bankAccount = info.get("bankAccount").toString();
			if(bankAccount.length()==Integer.parseInt(card_length)){
				result = true;
			} else {
				result = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("ShopApplyService|checkBankAccount", e);
		}
		return result;
	}

	/**
	 * 查询店铺申请信息
	 * @param map
	 * @return
	 */
	public HashMap queryAccountMap(HashMap<String, Object> map) {
		HashMap reMap = new HashMap();
		try {
			reMap = (HashMap)sqlSessionTemplate.selectOne("ShopApplyBean.queryAccountMap",map);
			infolog.info("ShopApplyService|queryAccountMap|reMap:"+reMap);
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|queryAccountMap", ex);
		} 
		return reMap = reMap == null ? new HashMap() : reMap;
	}

	/**
	 * 查询店铺信息
	 * @param map
	 * @return
	 */
	public HashMap queryShopMap(HashMap<String, Object> map) {
		HashMap reMap = new HashMap();
		try {
			reMap = (HashMap)sqlSessionTemplate.selectOne("ShopApplyBean.queryShopMap",map);
			infolog.info("ShopApplyService|queryShopMap|reMap:"+reMap);
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|queryShopMap", ex);
		} 
		return reMap = reMap == null ? new HashMap() : reMap;
	}

	/**
	 * 添加经营区域信息
	 * @param map
	 */
	public boolean insertShop(HashMap<String, Object> map) {
		boolean reValue = false;
		try {
			int f = sqlSessionTemplate.insert("ShopApplyBean.insertShop",map);
			reValue = true;
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|insertShop", ex);
		} 
		return reValue;
	}

	/**
	 * 更新店铺信息表信息
	 * @param map
	 * @return
	 */
	public boolean updateShop(HashMap<String, Object> map) {
		boolean reValue = false;
		try {
			int f = sqlSessionTemplate.update("ShopApplyBean.updateShop",map);
			reValue = true;
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|updateShop", ex);
		} 
		return reValue;
	}

	/**
	 * 更新店铺登录信息表中店铺申请信息
	 * @param map
	 * @return
	 */
	public boolean updateAccountShop(HashMap<String, Object> map) {
		boolean reValue = false;
		try {
			int f = sqlSessionTemplate.update("ShopApplyBean.updateAccountShop",map);
			reValue = true;
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("ShopApplyService|updateAccountShop", ex);
		} 
		return reValue;
	}

	
}
